//
//  SDHSportsFeedbackVC.m
//  SDHSportsNews
//
//  Created by MichaelShan on 2021/3/15.
//

#import "SDHSportsFeedbackVC.h"
#import "SDHSportsNotchScreenUtil.h"

@interface SDHSportsFeedbackVC ()

@property (nonatomic, strong) UITextView *tvFeedback;

@end

@implementation SDHSportsFeedbackVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initUI];
    
    self.title = @"Feedback";
    self.view.backgroundColor = UIColorFromRGB(48, 48, 48);
    UIBarButtonItem *right = [[UIBarButtonItem alloc] initWithTitle:@"submit" style:UIBarButtonItemStylePlain target:self action:@selector(submit)];
    self.navigationItem.rightBarButtonItem = right;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = NO;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    self.navigationController.navigationBar.hidden = YES;
}

- (void)submit {
    if (_tvFeedback.text.length < 10) {
        [MBProgressHUD showError:@"input less than 10 words"];
        return;;
    }
    
    [MBProgressHUD showLoading];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self submitSucceed];
    });
}

- (void)submitSucceed {
    [MBProgressHUD hideHUD];
    [MBProgressHUD showSuccess:@"submit succeed, we'll check your feedback, thanks"];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.navigationController popViewControllerAnimated:YES];
    });
}

- (void)initUI {
    UILabel *label = [UILabel new];
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont systemFontOfSize:16];
    label.text = @"Please input your feedback:";
    [self.view addSubview:label];
    
    CGFloat statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
    CGFloat navHeight = self.navigationController.navigationBar.frame.size.height;
    CGFloat notchHeight = [SDHSportsNotchScreenUtil getIPhoneNotchScreenHeight];
    notchHeight = 0;
    CGFloat posY =  statusBarHeight + navHeight + notchHeight + 20;
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(posY);
    }];

    
    UITextView *tv = [UITextView new];
    tv.clipsToBounds = YES;
    tv.layer.cornerRadius = 5;
    tv.layer.borderColor = [UIColor whiteColor].CGColor;
    tv.layer.borderWidth = 0.5;
    [self.view addSubview:tv];
    self.tvFeedback = tv;
    
    [tv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.equalTo(label.mas_bottom).offset(10);
        make.right.mas_equalTo(-10);
        make.height.mas_equalTo(200);
    }];
}

@end
